<template>
	<div class="game-container report-container">
		<div class="view-container dealer-container">
			<div class="params">
				<el-form
					ref="form"
					:inline="true"
					:model="queryData"
					label-width="auto"
				>
					<el-form-item :label="`${$t('common.belong_merchant')}:`">
						<merchant-select
							v-model="queryData.merchantId"
							:merchantInfo.sync="merchantObj"
						></merchant-select>
					</el-form-item>
					<el-form-item :label="`${$t('funds.transfer_time')}:`">
						<el-date-picker
							v-model="searchTime"
							size="medium"
							:picker-options="pickerOptions"
							format="yyyy-MM-dd HH:mm:ss"
							type="datetimerange"
							range-separator="-"
							:start-placeholder="$t('common.start_date')"
							:end-placeholder="$t('common.end_date')"
							align="right"
							:clearable="false"
							:default-time="defaultTime"
						></el-date-picker>
					</el-form-item>
					<el-form-item :label="`${$t('funds.order_no')}:`">
						<el-input
							v-model="queryData.outEventId"
							clearable
							size="medium"
							:placeholder="$t('common.please_enter')"
							:disabled="loading"
							@keyup.enter.native="enterSearch"
						></el-input>
					</el-form-item>
					<el-form-item
						:label="
							`${$t(
								'funds.proxy_member_funds_record.out_user_name'
							)}:`
						"
					>
						<el-input
							v-model="queryData.outUserName"
							clearable
							size="medium"
							:placeholder="$t('common.please_enter')"
							:disabled="loading"
							@keyup.enter.native="enterSearch"
						></el-input>
					</el-form-item>
					<el-form-item
						:label="
							`${$t(
								'funds.proxy_member_funds_record.in_user_name'
							)}:`
						"
					>
						<el-input
							v-model="queryData.inUserName"
							clearable
							size="medium"
							:placeholder="$t('common.please_enter')"
							:disabled="loading"
							@keyup.enter.native="enterSearch"
						></el-input>
					</el-form-item>
					<el-form-item
						:label="
							`${$t(
								'funds.proxy_member_funds_record.from_nallet'
							)}:`
						"
					>
						<el-select
							v-model="queryData.outAccountType"
							clearable
							:placeholder="$t('common.select_all')"
							:popper-append-to-body="false"
						>
							<el-option
								v-for="item in proxyWalletType"
								:key="item.code"
								:label="item.description"
								:value="item.code"
							></el-option>
						</el-select>
					</el-form-item>
					<el-form-item
						:label="
							`${$t(
								'funds.proxy_member_funds_record.order_status'
							)}:`
						"
					>
						<el-select
							v-model="queryData.orderStatus"
							clearable
							:placeholder="$t('common.select_all')"
							:popper-append-to-body="false"
						>
							<el-option
								:label="$t('common.success')"
								:value="1"
							></el-option>
							<el-option
								:label="$t('common.fail')"
								:value="2"
							></el-option>
						</el-select>
					</el-form-item>
					<el-form-item
						:label="
							`${$t(
								'funds.proxy_member_funds_record.transfer_amount'
							)}:`
						"
					>
						<el-input-number
							v-model="queryData.amountMin"
							size="medium"
							:placeholder="$t('common.minimum')"
							style="width: 100px"
							:min="0"
							:precision="0"
							:controls="false"
							name="amountMin"
							@blur="
								handleAmount(
									queryData,
									1,
									'amountMin',
									'amountMax',
									$t(
										'funds.proxy_member_funds_record.form_search_tip7'
									)
								)
							"
						></el-input-number>
						-
						<el-input-number
							v-model="queryData.amountMax"
							size="medium"
							:placeholder="$t('common.maximum')"
							style="width: 100px"
							:min="0"
							:precision="0"
							:controls="false"
							name="amountMax"
							@blur="
								handleAmount(
									queryData,
									2,
									'amountMin',
									'amountMax',
									$t(
										'funds.proxy_member_funds_record.form_search_tip8'
									)
								)
							"
						></el-input-number>
					</el-form-item>
					<el-form-item>
						<el-button
							type="primary"
							icon="el-icon-search"
							size="medium"
							@click="search"
						>
							{{ $t('common.search') }}
						</el-button>
						<el-button
							icon="el-icon-refresh-left"
							:disabled="loading"
							size="medium"
							@click="reset"
						>
							{{ $t('common.reset') }}
						</el-button>
						<el-button
							v-if="hasPermission('405041')"
							icon="el-icon-download"
							type="warning"
							:disabled="loading"
							size="medium"
							@click="handleExportExcel"
						>
							{{ $t('common.export') }}
						</el-button>
					</el-form-item>
				</el-form>
			</div>
			<div class="content">
				<el-table
					ref="tables"
					v-loading="loading"
					border
					size="mini"
					show-summary
					:data="tableData"
					style="width: 100%"
					class="small-size-table"
					:header-cell-style="getRowClass"
					element-loading-spinner="el-icon-loading"
					:summary-method="(val) => handleRow(val, subSummary)"
				>
					<el-table-column
						prop="outEventId"
						min-width="260"
						align="center"
						:label="$t('funds.order_no')"
					>
						<template slot-scope="scope">
							<Copy :title="scope.row.outEventId" :copy="copy">
								{{ scope.row.outEventId }}
							</Copy>
						</template>
					</el-table-column>
					<el-table-column
						prop="outMerchantId"
						min-width="200"
						align="center"
						:label="$t('common.belong_merchant')"
					>
						<template slot-scope="scope">
							{{ merchantFilter(scope.row.outMerchantId) }}
						</template>
					</el-table-column>
					<el-table-column
						prop="outUserName"
						min-width="200"
						align="center"
						:label="
							$t('funds.proxy_member_funds_record.out_user_name')
						"
					>
						<template slot-scope="scope">
							<Copy :title="scope.row.outUserName" :copy="copy">
								{{ scope.row.outUserName }}
							</Copy>
						</template>
					</el-table-column>
					<el-table-column
						prop="outUserLevel"
						align="center"
						:label="
							$t('funds.proxy_member_funds_record.out_user_level')
						"
						min-width="200"
					>
						<template slot-scope="scope">
							{{
								scope.row.outUserLevel === null
									? '-'
									: scope.row.outUserLevel
							}}
						</template>
					</el-table-column>
					<el-table-column
						prop="inUserName"
						min-width="200"
						align="center"
						:label="
							$t('funds.proxy_member_funds_record.in_user_name')
						"
					>
						<template slot-scope="scope">
							<Copy :title="scope.row.inUserName" :copy="copy">
								{{ scope.row.inUserName }}
							</Copy>
						</template>
					</el-table-column>
					<el-table-column
						prop="outAccountType"
						align="center"
						:label="
							$t('funds.proxy_member_funds_record.from_nallet')
						"
						min-width="200"
					>
						<template slot-scope="scope">
							{{
								typeFilter(
									scope.row.outAccountType,
									'proxyWalletType'
								)
							}}
						</template>
					</el-table-column>
					<el-table-column
						prop="orderStatus"
						align="center"
						:label="
							$t('funds.proxy_member_funds_record.order_status')
						"
						min-width="200"
					>
						<template slot-scope="scope">
							<span v-if="scope.row.orderStatus === 1">
								{{ $t('common.success') }}
							</span>
							<span v-if="scope.row.orderStatus === 2">
								{{ $t('common.fail') }}
							</span>
						</template>
					</el-table-column>
					<el-table-column
						prop="amount"
						align="center"
						min-width="200"
						:label="
							$t(
								'funds.proxy_member_funds_record.transfer_amount'
							)
						"
					>
						<template slot-scope="scope">
							{{
								handleTotalNumber(
									scope.row.currency,
									scope.row.amount
								)
							}}
						</template>
					</el-table-column>
					<el-table-column
						prop="createdAt"
						align="center"
						:label="$t('funds.transfer_time')"
						min-width="300"
					></el-table-column>
					<el-table-column
						prop="remark"
						align="center"
						:label="$t('common.remark')"
						min-width="300"
					>
						<template slot-scope="scope">
							{{ scope.row.remark || '-' }}
						</template>
					</el-table-column>
				</el-table>
				<!-- 分页 -->
				<el-pagination
					:current-page.sync="pageNum"
					class="pageValue"
					background
					layout="total, sizes,prev, pager, next, jumper"
					:page-size="pageSize"
					:page-sizes="pageSizes"
					:total="total"
					@current-change="handleCurrentChange"
					@size-change="handleSizeChange"
				></el-pagination>
			</div>
		</div>
	</div>
</template>

<script>
// 新版代理转账记录、需要结合原型调整
import list from '@/mixins/list'
import dayjs from 'dayjs'
import { routerNames } from '@/utils/consts'
import summaryList from './components/summaryList'
const end = dayjs().endOf('day')
const start = dayjs().startOf('day')
export default {
	name: routerNames.proxyTransferRecord,
	mixins: [list, summaryList],
	data() {
		return {
			queryData: {},
			searchTime: [start, end],
			accountFlag: 'playerName',
			tableData: [],
			accountBizDicList: [],
			accountChangeDic: [],
			subSummary: {},
			merchantObj: ''
		}
	},
	computed: {
		proxyWalletType() {
			return this.globalDics.proxyWalletType || []
		}
	},
	methods: {
		loadData() {
			const timeArr = this.searchTime || []
			const params = {
				...this.queryData,
				createdTimeStart: dayjs(timeArr[0]).format(
					'YYYY-MM-DD HH:mm:ss'
				),
				createdTimeEnd: dayjs(timeArr[1]).format('YYYY-MM-DD HH:mm:ss'),
				...this.getParams()
			}
			this.pageCurrency = this.merchantObj?.currency || ''
			this.$api
				.getProxyFundsRecordsProxyTransferList(params)
				.then((res) => {
					this.loading = false
					const { record, totalRecord, summary } = res.data || {}
					this.tableData = record || []
					this.total = totalRecord
					this.subSummary = summary || {}
				})
				.catch(() => {
					this.loading = false
				})
		},

		reset() {
			this.queryData = {}
			this.merchantObj = ''
			this.searchTime = [start, end]
			this.pageNum = 1
			this.loadData()
		},
		handleExportExcel() {
			const timeArr = this.searchTime || []
			const params = {
				...this.queryData,
				createdTimeStart: dayjs(timeArr[0]).format(
					'YYYY-MM-DD HH:mm:ss'
				),
				createdTimeEnd: dayjs(timeArr[1]).format('YYYY-MM-DD HH:mm:ss')
			}
			this.exportExcel(params)
		}
	}
}
</script>

<style lang="scss" scoped>
::v-deep .el-table__fixed-footer-wrapper .cell,
::v-deep .el-table__footer-wrapper .cell {
	height: 100%;
	padding: 0 !important;
	margin: 0 !important;
	> div {
		height: 100%;
	}
}
::v-deep .footer_count_row {
	min-height: 50px;
	height: 50%;
	display: flex;
	font-weight: 700;
	padding: 5px 0;
	align-items: center;
	flex-direction: column;
	justify-content: center;
}
::v-deep .footer_count_row_border {
	border-top: 1px solid #ebeef5;
}
</style>
